<!doctype html>
<html lang="en" class="fixed">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>权限编辑</title>
    <link rel="apple-touch-icon" sizes="120x120" href="favicon/apple-icon-120x120.png">
    <link rel="icon" type="image/png" sizes="192x192" href="favicon/android-icon-192x192.png">
    <link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
    <link rel="stylesheet" type="text/css"
          href="<?php xcho(loadSource('/assets/plugins/bootstrap/css/bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/animate.css/animate.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/font-awesome/css/font-awesome.css')) ?>">
    <link rel="stylesheet"
          href="<?php xcho(loadSource('/assets/plugins/data-table/media/css/dataTables.bootstrap.min.css')) ?>">

    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/ztree/css/zTreeStyle/zTreeStyle.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/style.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/app.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/layui/css/layui.css')) ?>" media="all">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/css/new_main.css')) ?>">
    
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        ul,li,ol,li{
            list-style: none;
        }
        a{
            color:#000;
            text-decoration: none;
        }
        body{
            background: #F4F4F4;
        }
        .content{
            width: 1200px;
            margin: 0 auto;
            padding: 20px 30px;
            background: #fff;
        }
        .content .title .title-role p{

        }
        .content .title .title-role .title-btn{
            float: right;
            margin-top: -30px;
        }
        .content .title .title-role .title-btn button{
            padding: 6px 10px;
            margin: 0 4px;
            border-radius: 5px;
        }
        .content .title .title-role .title-btn button:nth-of-type(1){
            background: #108EE9;
            color:#fff;
            border: none;
            font-size: 12px;
        }
        .content .title .title-role .title-btn button:nth-of-type(2){
            background: #108EE9;
            color:#fff;
            border: none;
            font-size: 12px;
        }
        .content .title .title-role .title-btn button:nth-of-type(3){
            background: #D75234;
            color:#fff;
            border: none;
            font-size: 12px;
        }
        .content .title h2{
            width: 100%;
            padding: 10px 20px;
            font-size: 12px;
            background: #f4f4f4;
            border-radius: 5px;
            margin-top: 24px;
        }
        .content .title p.name{
            font-size: 12px;
            margin-top: 20px;
        }
        .content .title p.name input{
            width: 180px;
            height: 24px;
            border: 1px #ccc solid;
            border-radius: 5px;
            text-indent: 10px;
        }
        .content .title p.name span{
            margin-left: 40px;
        }
        .content .module h3{
            font-size: 12px;
            width: 100%;
            background: #f4f4f4;
            padding: 10px 20px;
            border-radius: 5px;
        }
        .content .module .module-content{
            margin-top: 30px;
            padding-right: 30px;
        }
        .content .module .module-content ul{
            display: inline-block;
            border: 1px #eee solid;
        }
        .content .module .module-content ul li{
            border-bottom: 1px #eee solid;
            line-height: 30px;
            padding: 0 30px;
            font-size: 12px;
            color: #333;
            cursor: pointer;
        }
        .content .module .module-content ul li:last-child{
            border-bottom: none;
        }
        .content .module .module-content ul li:hover{
            background: #E7F4FD;
            color:#3F93EC;
        }
        .content .module .module-content ul li.active{
            background: #E7F4FD;
            color:#3F93EC;
        }
        .content .module .module-content .module-tabs{
            float: right;
            width: 80%;
        }
        .content .module .module-content .module-tabs>div{
            display: none;
            width: 100%;
        }
        .content .module .module-content .module-tabs .one:nth-of-type(1){
            display: inline-block;
        }
        .content .module .module-content .module-tabs .one table{
            width: 100%;
        }
        .content .module .module-content .module-tabs .one table thead{
            background: #f4f4f4;
        }
        .content .module .module-content .module-tabs .one table thead tr th{
            padding: 10px 20px;
            border: 1px #eee solid;
            font-size: 12px;
        }
        .content .module .module-content .module-tabs .one table tbody tr td{
            border: 1px #eee solid;
            padding: 10px;
            font-size: 12px;
        }
        .content .module .module-content .module-tabs .one table tbody tr td span{
            margin: 0 4px;
        }
        .content .module .module-content .module-tabs .one table tbody tr td:last-child{
            color:#008DE7;
        }
    </style>
</head>

<body><?php include_once TPL_PATH . 'public/nav.phtml'; ?>

<div class="wrap">
    <div class="content">
        <div class="title">
            <div class="top_pages bottom_pages" style="float: right">
                <button class="layui-btn layui-btn-small" id="save">保存</button>
                <button style="margin-left: 24px" class="layui-btn layui-btn-primary layui-btn-small" id="return">取消</button>
            </div>
            <div class="title-role">
                <p>数据权限 / <?php xcho($roledata['data']['cn_name'])?></p>
            </div>
            <h2>基本信息</h2>
            <div class="row">
                <div class="col-xs-6">
                    <label class="col-sm-3 control-label" style="line-height: 34px;text-align: right">角色名称:</label>
                    <div class="col-sm-9">
                        <input class="form-control" disabled name="role_name" type="text"
                               value="<?php xcho($roledata['data']['cn_name'])?>" placeholder="角色名称">
                    </div>
                </div>
                <div class="col-xs-6">
                    <label class="col-sm-3 control-label" style="line-height: 34px;text-align: right">上级角色:</label>
                    <div class="col-sm-9">
                        <input class="form-control" disabled  id="role-picker" name="group_id" type="text"
                               value="<?php xcho($roledata['data']['parent_name'])?>" placeholder="上级角色">
                    </div>
                </div>
            </div>
        </div>
        <div class="module">
            <h3>模块权限</h3>
            <div class="module-content">
                <ul>
                    <?php foreach ($datalist['data'] as $aList){?>
                        <li><?php xcho($aList['model_name'])?></li>
                    <?php }?>
                </ul>
                <div class="module-tabs">
                    <?php foreach ($datalist['data'] as $aList){?>
                    <div class="one  layui-form" >
                        <table>
                            <thead>
                            <th>配置数据</th>
                            <th>不可读</th>
                            <th>不可写</th>
                            </thead>
                            <tbody data-model="<?php xcho($aList['model_val'])?>" class="<?php xcho($aList['model_val'])?>">
                            <?php foreach ($aList['data'] as $aField){?>
                                <tr>
                                    <td><?php xcho($aField['key_name'])?></td>
                                    <td>
                                        <input type="checkbox"  data-prop="no_read" class="no_read" lay-skin="primary"
                                               data-name="<?php xcho($aField['key_val'])?>" name="<?php xcho($aField['key_val'])?>"
                                            <?php if(array_key_exists($aList['model_val'],$modeldata)){
                                                if(in_array($aField['key_val'],$modeldata[$aList['model_val']]['no_read'])){
                                                    xcho('checked');
                                                }
                                            }?>>
                                    </td>
                                    <td>
                                        <input type="checkbox" data-prop="no_write" class="no_write" lay-skin="primary"
                                               data-name="<?php xcho($aField['key_val'])?>" name="<?php xcho($aField['key_val'])?>"
                                            <?php if(array_key_exists($aList['model_val'],$modeldata)){
                                                if(in_array($aField['key_val'],$modeldata[$aList['model_val']]['no_write'])){
                                                    xcho('checked');
                                                }
                                            }?>>
                                    </td>
                                </tr>
                            <?php }?>
                            </tbody>
                        </table>
                    </div>
                    <?php }?>
                </div>
            </div>
            <div style="clear: both"></div>
        </div>
    </div>
</div>
<input type="hidden" name="list" value="<?php xcho($list) ?>"/>
<input type="hidden" name="save" value="<?php xcho($save) ?>"/>
<script src="<?php xcho(loadSource('/assets/plugins/jquery/jquery.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/bootstrap/js/bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/jquery.dataTables.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/dataTables.bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layer-v3.0.3/layer/layer.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layui/layui.all.js')) ?>" charset="utf-8"></script>
<script
    src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/dataTables.responsive.min.js')) ?>"></script>
<script
    src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/responsive.bootstrap.min.js')) ?>"></script>
<script
    src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/responsive.bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.core.js')) ?>"></script>
<script type="text/javascript" src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.excheck.js')) ?>"></script>
<script type="text/javascript" src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.exedit.js')) ?>"></script>
<script>
    $(function () {
        $(".module-content>ul>li").on("click",function(){
            var ind=$(this).index();
            $(this).addClass("active").siblings("li").removeClass("active");
            $(".module-content>.module-tabs>div").eq(ind).slideDown(200).siblings("div").slideUp(200);
        })
        //返回列表页
        $("#return").on("click",function(){
            location.href = "/sysmanager/role_privilege/roleList"
        })
        //保存编辑内容
        $("#save").on("click",function () {
            var role_id = getUrlParam("id");
            var data = [];
            $("tbody").each(function () {
                var model = $(this).attr("data-model");
                var item = {},no_read = [],no_write = [];
                item.model = model;
                item.pk = role_id+"_"+model;
                $(this).find('input[type="checkbox"]:checked').each(function () {
                    if($(this).attr("data-prop") == "no_read"){
                        no_read.push($(this).attr("data-name"));
                    }else if($(this).attr("data-prop") == "no_write"){
                        no_write.push($(this).attr("data-name"))
                    }
                });
                item.no_read = no_read||"";
                item.no_write = no_write||"";
                data.push(item);
            })
            console.log(data);

            $.ajax({
                url: $("input[name='save']").val(),
                data: {
                    role_id: role_id,
                    data: data
                },
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    console.log(data)
                    if(data.success == 1){
                        layer.alert('保存成功!', {
                            skin: 'layui-layer-molv'
                        },function (){
                            location.reload();
                        });
                    }else{
                        layer.alert('保存失败！', {
                            skin: 'layui-layer-molv'
                        },function (){
                            location.reload();
                        });
                    }
                },
                complete:function(){

                },
                error: function () {

                }
            });
        })
        //获取url中的参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]); return null; //返回参数值
        }
    });
</script>
<?php include_once TPL_PATH . 'public/foot_script.phtml'; ?>

<button id="top" style="height: 50px;width: 50px;"></button></body>

</html>
